package com.imti.controller;

import com.imti.model.Exam;
import com.imti.service.ExamManageService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/exams")
public class ExamManageController {
    @Resource
    private ExamManageService examManageService;

    /**
     * 查询考试列表信息
     * @return
     */
    @RequestMapping("/exam")
    public String findAllExam(HttpServletRequest request){
        List<Exam> allExam = examManageService.findAllExam();
        request.setAttribute("examList",allExam);
        return "/exam/exam-list";
    }
    //先跳转exam-add页面
    @RequestMapping("/addExams")
    public String addExams(){
        return "/exam/exam-add";
    }

    @RequestMapping("/add")
    public String addExamById(Exam exam){
        examManageService.addExamById(exam);
        System.out.println(exam);
        return "redirect:/exams/exam";
    }

    @RequestMapping("/updateExams/{id}")
    public String updateExamsById(@PathVariable("id") Integer id, Model model){
        Exam exam = examManageService.updateExamsById(id);
        model.addAttribute("allExam",exam);
        return "/exam/exam-update";
    }
    @RequestMapping("/update")
    public String update(Exam exam){
        examManageService.update(exam);
        return "redirect:/exams/exam";
    }
}
